﻿namespace ElisVK.Data.AudioSources
{
    using System.Text;
    using Utils;

    public class VKFriendsAudioSource : AudioSource
    {
        public VKFriendsAudioSource() : base("VK Friends", true)
        {
        }
        
        protected override void LoadChildren()
        {
            var buff = VKHelper.DownloadData(
                "https://api.vkontakte.ru/method/friends.get.xml?fields=uid,first_name,last_name&access_token=" +
                App.SessionInfo.AccessToken);

            var friendsList = UserInfo.ParseUserInfosFromXML(Encoding.UTF8.GetString(buff));

            friendsList.Sort();

            foreach (var friend in friendsList)
            {
                Children.Add(new VKFriendAudioSource(friend));
            }
        }
    }
}
